package com.wjy.common.util;

import com.wjy.common.bean.mail.MailBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;

/**
 * @author wjy
 * @data 2019年3月11日
 * @desc 发送电子邮件
 */
@Component
public class MailUtil {

    @Autowired
    private JavaMailSenderImpl mailSender;

    public void sendSimpleMail(MailBean bean) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();

        simpleMailMessage.setFrom(bean.getFrom());
        simpleMailMessage.setTo(bean.getTo());
        simpleMailMessage.setSubject(bean.getSubject());
        simpleMailMessage.setText(bean.getText());

        try {
            mailSender.send(simpleMailMessage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
